package com.walkline.smzdm.dao;

import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;
import com.walkline.smzdm.SMZDMException;
import com.walkline.smzdm.SMZDMSDK;
import com.walkline.smzdm.inf.ExperienceDetails;
import com.walkline.util.StringUtility;

public class SMZDMExperienceDetails extends SMZDMObject implements ExperienceDetails
{
	private int _error = 0;
	private String _title = "";
	private String _img = "";
	private String _simg = "";
	private String _bimg = "";
	private String _type = "";
	private String _status = "";
	private String _content = "";
	private String _author = "";
	private String _user_id = "";
	private String _avatar = "";
	private int _date_time = 0;
	private String _comment_count = "";
	private String _fav_count = "";
	private String _love_count = "";
	private String _btn_url = "";
	private String _detail_url = "";
	private int _create_time = 0;
	private String _prev_id = "";
	private String _prev_title = "";
	private String _next_id = "";
	private String _next_title = "";
	private String[] _content_img_list;
	private String _series_block = "";

	public SMZDMExperienceDetails(SMZDMSDK smzdm, JSONObject jsonObject) throws SMZDMException
	{
		super(smzdm, jsonObject);

		JSONObject details = jsonObject;
		if (details != null)
		{
			_error = details.optInt("error");

			JSONObject detailsObject = details.optJSONObject("data");
			if (detailsObject != null)
			{
				_title = detailsObject.optString("title");
				_img = detailsObject.optString("img");
				_simg = detailsObject.optString("simg");
				_bimg = detailsObject.optString("bimg");
				_type = detailsObject.optString("type");
				_status = detailsObject.optString("status");
				_content = detailsObject.optString("content");
				_author = detailsObject.optString("author");
				_user_id = detailsObject.optString("user_id");
				_avatar = detailsObject.optString("avatar");
				_date_time = detailsObject.optInt("datetime");
				_comment_count = detailsObject.optString("commentcount");
				_fav_count = detailsObject.optString("favcount");
				_love_count = detailsObject.optString("lovecount");
				_btn_url = detailsObject.optString("btnurl");
				_detail_url = detailsObject.optString("detail_url");
				_create_time = detailsObject.optInt("create_time");
				_prev_id = detailsObject.optString("previd");
				_prev_title = detailsObject.optString("prevtitle");
				_next_id = detailsObject.optString("nextid");
				_next_title = detailsObject.optString("nexttitle");

				JSONArray imgList = detailsObject.optJSONArray("content_img_list");
				if (imgList != null)
				{
					_content_img_list = new String[imgList.length()];
					JSONObject imgListObject;
					for (int i=0; i<imgList.length(); i++)
					{
						try {
							_content_img_list[i] = imgList.getString(i);
							//imgListObject = (JSONObject) imgList.get(i);
							//_content_img_list[i] = imgListObject.toString();
						} catch (JSONException e) {}
					}
				}

				//for (int i=0; i<_content_img_list.length; i++)
				//{
				//	_content = StringUtility.replace(_content, "http://res.smzdm.com/images/loading2x.png", _content_img_list[i]);
				//}

				_series_block = detailsObject.optString("series_block");
			}
		}
	}

	public int getError() {return _error;}

	public String getTitle() {return _title;}

	public String getImg() {return _img;}

	public String getSImg() {return _simg;}

	public String getBImg() {return _bimg;}

	public String getType() {return _type;}

	public String getStatus() {return _status;}

	public String getContent() {return _content;}

	public String getAuthor() {return _author;}

	public String getUserId() {return _user_id;}

	public String getAvatar() {return _avatar;}

	public int getDateTime() {return _date_time;}

	public String getCommentCount() {return _comment_count;}

	public String getFavCount() {return _fav_count;}

	public String getLoveCount() {return _love_count;}

	public String getBtnUrl() {return _btn_url;}

	public String getDetailUrl() {return _detail_url;}

	public int getCreateTime() {return _create_time;}

	public String getPrevId() {return _prev_id;}

	public String getPrevTitle() {return _prev_title;}

	public String getNextId() {return _next_id;}

	public String getNextTitle() {return _next_title;}

	public String[] getContentImgList() {return _content_img_list;}

	public String getSeriesBlock() {return _series_block;}
}